<template>
  <div>
    <van-nav-bar title="编辑资料" left-text="返回" left-arrow @click-left="onClickLeft" />

    <Comment :commentData="item" :logoImg="$axios.defaults.baseURL + commentList[index].user.head_img" v-for="(item, index) in commentList" :key="item.id" @callReply="callReply" />
    <commentInput @reloadComment="loadComment" ref="commentInput" :parentInfo="commentInfo" />
  </div>
</template>

<script>
import { Toast } from 'vant'
import Comment from '../components/comment/index'
import commentInput from '../components/commentInput'
export default {
  components: {
    Comment,
    commentInput
  },
  data() {
    return {
      commentList: [],
      commentInfo: {}
    }
  },
  created() {
    // this.$axios({
    //   url: '/post_comment/' + this.$route.params.id
    // }).then(res => {
    //   // console.log(res.data)
    //   // if (res.data.data.length >= 3) {
    //   //   res.data.data.length = 3
    //   // }
    //   this.commentList = res.data.data
    //   // console.log(this.commentList)
    // })
    this.loadComment()
  },

  methods: {
    callReply(commentInfo) {
      this.commentInfo = commentInfo
      this.$refs.commentInput.showTextarea()
    },
    loadComment() {
      this.$axios({
        url: '/post_comment/' + this.$route.params.id
      }).then(res => {
        this.commentList = res.data.data
      })
    },
    onClickLeft() {
      this.$router.back()
      Toast('返回')
    }
  }
}
</script>

<style></style>
